#pragma once

#include "NirSet.h"
#include "NirMap.h"
#include "NirTwoVector.h"
#include "Vertex.h"
#include "AsLink.h"
#include "BgpMessage.h"

#define ATTACKER_ID 0
#define VICTIM_ID 1

class As : public Vertex
{
public:
	As(int id);
	virtual ~As();

	void PrintEdges();

	void AddCustomer(As *as);
	void AddProvider(As *as);
	void AddPeer(As *as);

	Set<As*> GetCustomers(){ return _customers; }
	Set<As*> GetProvides(){ return _providers; }
	Set<As*> GetPeers(){ return _peers; }
	Map<As*, Vector<As*> > GetSelectedPaths(){ return _selectedPaths; }

	virtual void UpdateOnRcvSelectedPathsFromNeighbor(As* pSender, BgpMessage& pMsg);
	virtual void InitialIntroduceMyselfToNeighbors();
	virtual void BgpIteration();
	bool WasUpdateOnSelectedPaths; // true iff there was update in the last BGP iteration

	void NullifyBgp();


public:
	Set<As*> _customers;
	Set<As*> _providers;
	Set<As*> _peers;

	Map<As*, Vector<As*> > _selectedPaths; // Bgp Routing Information Bases(RIBs)
	Map<As*, Vector<As*> > _lastIterationUpdatedPaths;
	Map<As*, Vector<As*> > _currentIterationUpdatedPaths;
	
	bool IsPeer(As* pOther);
	bool IsCustomer(As* pOther);
	bool IsProvider(As* pOther);

	bool IsRelationExist(As* pSender, Set<As*>& pRelation); // Help function for isPeer, isCustomer, isProvider

	bool operator==(const As& other) const
	{
		return _name == other._name;
	}
	bool operator!=(const As& other) const
	{
		return !operator==(other);
	}
};

